*Create CDX time series for HY and iG

import delimited /Users/ym2701/Dropbox/FundingbyDebtEquity/empirical/data/markitcdx/cdxSeries.csv, clear 


keep if compspr!="NA"

sort date name maturity

by date name: keep if _n==_N


*genrate var
gen id=substr(name,-2,2)
gen year=substr(date,1,4)
gen month=substr(date,6,2)
gen day=substr(date,9,2)


*keep 

keep date year month day id compspr modspr


*destring

destring compspr, replace
replace modspr="" if modspr=="NA"
destring modspr, replace
destring year, replace
destring month, replace
destring day, replace


sort id year month day 

save "/Users/ym2701/Dropbox/FundingbyDebtEquity/empirical/data/markitcdx/cdxuscorpclean.dta", replace
